<?php
$this->headScript()->prependFile($this->baseUrl() . '/public/scripts/access.js');
?>


<article class="module width_full">
    <header><h3>Permisos para el grupo de usuarios "<?php echo $this->name ?>"</h3></header>
    <!--  add by gary  -->
    <div class="module_content">
        <?php foreach ($this->names_modules as $module): ?>
            <div style="width: 400px;">
                <h2 style="text-transform: uppercase"><?php echo $module->module ?></h2>
                <table style="width: 450px;">
                    <thead>
                        <tr>
                            <td><b>Recurso</b></td>
                            <td><b>Descripci&oacute;n</b></td>
                            <td><b>Permiso</b></td>
                            <td><b>Visible(Menu)</b></td>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($this->allResources as $resource): ?>
                            <?php if ($resource->module == $module->module) : ?>
                                <tr>
                                    <td><?php echo $resource->name; ?></td>
                                    <td><?php echo $resource->description; ?></td>
                                    <?php
                                    $checkResource = ''; $checkVisible = '';
                                    foreach ($this->group_resource as $gr) {
                                        if ($gr->idresource == $resource->idresource) {
                                            $checkResource = 'checked="checked"';
                                            if($gr->visible == 1)
                                                $checkVisible = 'checked="checked"';
                                        }
                                    }
                                    ?>
                                    <td style="text-align: center">
                                        <input type="checkbox" value="<?php echo $resource->idresource; ?>" <?php echo $checkResource; ?> onclick="access('<?php echo $this->id ?>', this.value, '<?php echo $this->baseUrl() . '/admin/admin/access' ?>', this)"/>
                                    </td>
                                    <td style="text-align: center">
                                        <input type="checkbox" value="<?php echo $resource->idresource; ?>" <?php echo $checkVisible; ?> onclick="visible('<?php echo $this->id ?>', this.value, '<?php echo $this->baseUrl() . '/admin/admin/visible' ?>', this)" />
                                    </td>
                                </tr>
                            <?php endif; ?>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        <?php endforeach; ?>
    </div>
    <!--  end add by gary  -->
    
    <!--    <div class="module_contenst">
    <?php foreach ($this->modules as $mod) { ?>
        
        <?php
        $resources = new Admin_Model_DbTable_Resources();
        $controllers = $resources->getControllers($mod['module']);
        ?>
                    <h3><?php echo $mod['module'] ?></h3>
        
        <?php foreach ($controllers as $controller) { ?>
                            <table cellspacing="0">
                                <tr>
            <?php
            $names = $resources->getNames($mod['module'], $controller['controller']);
            ?>
            <?php foreach ($names as $n) { ?>
                                            <td><?php echo $n['name'] ?></td>
            <?php } ?>
                                </tr>
                                <tr>
                                    <td><b><?php echo $controller['controller'] ?></b></td>
            <?php $actions = $resources->getActions($mod['module'], $controller['controller']) ?>
            <?php foreach ($actions as $action) { ?>
                <?php
                $g_r = new Admin_Model_DbTable_Access();
                $check = '';
                if ($g_r->tieneAcceso($this->id, $action['idresource']))
                    $check = 'checked'
                    ?>
                                            <td><input <?php echo $check; ?>  type="checkbox" value="<?php echo $action['idresource'] ?>" onclick="access('<?php echo $this->id ?>', this.value, '<?php echo $this->baseUrl() . '/admin/admin/access' ?>', this)" ></td>
            <?php } ?>
                                </tr>
        <?php } ?>
                    </table>
        
    <?php } ?>
    
        </div>-->
</article>  

<style>
    .module_contenst h3{
        background: #CCC;
        padding: 5px;
        margin: 10px 0 !important;  
    }

    .module_contenst tr td{
        border: 1px solid #eee;
        padding: 5px;
    }

    .module_contenst table{
        border: 1px solid #eee
    }
</style>